<template>
  <div> 
    <basic-container>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>产品配置</el-breadcrumb-item> 
        <el-breadcrumb-item>测试工具</el-breadcrumb-item>
        <el-breadcrumb-item>鱼摆摆变更</el-breadcrumb-item>
      </el-breadcrumb>
    </basic-container>
    <basic-container>
      <el-form ref="form" :model="form" label-width="80px" class="demo-form-inline">
        <el-form-item label="用户id">
          <el-input v-model="form.uid"></el-input>
        </el-form-item>
        <el-form-item label="鱼摆摆">
          <el-input type="number" v-model="form.count"></el-input>
          <div style="color : red">如果鱼摆摆为负数，则是减鱼摆摆。每次最多加10000元</div>
        </el-form-item>

        <el-form-item label="用户信息:">
            <div>手机号={{user.phone}}</div>
            <div>昵称={{user.user_name}}</div>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">充值</el-button>
          <el-button type="success" @click="onSubmitChange">检查用户</el-button>
        </el-form-item>
      </el-form>
    </basic-container>
  </div>
</template>
<script>
import { common } from "@/api/cat/httpRequest";
import { tools as baseURL } from "@/api/cat/baseUrls";
export default {
  data() {
    return {
      form: {},
      user:{}
    };
  },
  methods: {
    /** 检测用户 */
    async onSubmitChange(){
      if(this.form.uid==undefined){
        this.$message.error("请输入用户id")
        return;
      }
      let {data} = await common(baseURL.changeUser+'/'+this.form.uid, null, null, "GET");
      if (data == null || data.length==0) {
        this.user = {}
        this.$message.error("用户不存在")
        return;
      } 
      this.user = data;
    },
    /** 变更 */
    async onSubmit() {
      if(this.form.count==undefined){
        this.$message.error("请输入鱼摆摆")
        return;
      }
      if(this.form.count>10000){
        this.$message.error("鱼摆摆不可大于10000")
        return;
      }
      if(this.form.uid==undefined){
        this.$message.error("请输入用户id")
        return;
      }

      
      this.$confirm("确定要给此用户充值吗?, 是否继续?", "提示", {
        type: "warning",
      })
      .then(async () => {
        let {data} = await common(baseURL.changeUser+'/'+this.form.uid, null, null, "GET");
        if (data == null || data.length==0) {
          this.user = {}
          this.$message.error("用户不存在")
          return;
        }
        let response = await common(baseURL.beansChange+'/'+this.form.uid+'/'+this.form.count+'/2',null, null, "GET");
      })
      
    },
  },
};
</script>